<template>
  <div class="base-container" id="main">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="标准名称" name="projectName">
            <t-input
              v-model="queryParams.projectName"
              clearable
              placeholder="请输入标准名称"
              style="width: 240px"
            />
          </t-form-item>
           <t-form-item label="制定或修订" name="formulateType">
            <t-select style="width: 240px" clearable v-model="queryParams.formulateType"
                      :options="dict.type.formulate_type">
            </t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-table rowKey="index" size="small" :data="data" :columns="columns" hover :pagination="pagination"
      :loading="dataLoading" :sort="sort" :hideSortTips="true" @sort-change="sortChange">
      <template #projectName="{ row }">
        <t-link @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_detail=true" hover="color" theme="primary">{{ row.projectName }}</t-link>
      </template>
      <template #formulateType="{ row }">
        {{ row.formulateType | filterByDict(dict.type.formulate_type) }}
      </template>
      <template #manageDeptId="{ row }">
        {{ row.manageDeptId | filterByTree(deptMenuOptions) }}
      </template>
      <template #approveStatus="{ row }">
        <t-tag @click="" class="cursor-pointer" v-if="row.projectStatus === '1'" theme="warning"
          variant="light">暂存</t-tag>
        <t-tag @click="" class="cursor-pointer" v-else-if="row.projectStatus === '2'" theme="primary"
          variant="light">提交</t-tag>
      </template>
      <template #op="{ row }">
        <t-button size="small" @click="opinionVisible = true; header = row.projectName; nowRow = row" variant="text"
          class="t-button-link">
          <t-icon name="edit-1" slot="icon" />
          评价
        </t-button>
      </template>
    </t-table>
    <t-dialog :visible.sync="opinionVisible" confirmBtn="提交" width="40%" :header="header"
      :cancelBtn="null">
      <t-form @submit="onSubmit" labelWidth="160px" :colon="true">
        <t-form-item label="地方标准章条编号" name="chapterNum">
          <t-input v-model="formData.chapterNum" placeholder="请输入地方标准章条编号" />
        </t-form-item>
        <t-form-item label="意见内容" name="opinion">
          <t-textarea v-model="formData.opinion" :autosize="{ minRows: 3 }" placeholder="请输入您的意见" />
        </t-form-item>
        <t-form-item label="处理意见内容" name="dealOpinion">
          <t-textarea v-model="formData.dealOpinion" :autosize="{ minRows: 3 }" placeholder="请输入您的意见" />
        </t-form-item>
        <t-form-item label="您的名字" name="opinionSource">
          <t-input v-model="formData.opinionSource" placeholder="请输入您的名字或单位名" />
        </t-form-item>
        <t-form-item label="您的单位名" name="opinionSource">
          <t-input v-model="formData.opinionSource" placeholder="请输入您的名字或单位名" />
        </t-form-item>
        <t-row>
          <t-col :span="12" class="operation-container">
            <t-button theme="default" variant="outline" type="reset" @click="opinionVisible = false">取消</t-button>
            <t-button theme="primary" type="submit"> 提交</t-button>
          </t-col>
        </t-row>
      </t-form>
    </t-dialog>
    <standardDetailDialog  :header="dialog.header" :objId="dialog.objId"  :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
    </standardDetailDialog>
  </div>
</template>

<script>
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";

export default {
  name: "opinion-add",
  components: {
    standardDetailDialog
  },
  dicts: ["formulate_type"],
  data() {
    return {
      nowRow: {},
      dialog: {
        objId: "",
        header: "",
        open_detail: false,
      },
      deptMenuOptions: [],
      header: "",
      // rules: {
      //   chapterNum: [
      //     {
      //       required: true,
      //       message: "地方标准章条编号不能为空",
      //     },
      //   ],
      //   opinion: [
      //     { required: true, message: "意见内容不能为空" }
      //   ],
      //   opinionSource: [
      //     { required: true, message: "提出人或单位不能为空" }
      //   ],
      //   dealOpinion: [
      //     { required: true, message: "处理意见不能为空" }
      //   ],
      // },
      formData: {
        chapterNum: "",
        opinion: "",
        opinionSource: "",
        dealOpinion: ""
      },
      columns: [
        {
          colKey: "projectName",
          title: "标准名称",
          align: "center",
          width: 220

        },
        {
          colKey: "linkMan",
          title: "联系人",
          align: "center",
          width: 160,
        },
        {
          colKey: "linkWay",
          title: "联系方式",
          align: "center",
          width: 160,
        },
        {
          colKey: "formulateType",
          title: "制定或修订",
          align: "center",
          width: 160,
        },
        {
          colKey: "reviseNum",
          title: "被修订标准号",
          align: "center",
          width: 160,
        },
        {
          colKey: "consistencyDegree",
          title: "一致性程度",
          align: "center",
          width: 160,
        },
        {
          colKey: "internationalStandardNum",
          title: "国际标准号",
          align: "center",
          width: 160,
        },
        {
          colKey: "manageDeptId",
          title: "主管部门",
          align: "center",
          width: 160,
        },
        {
          colKey: "completeDate",
          title: "完成时间",
          align: "center",
          width: 160,
          sorter: true,
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120,
          fixed: 'right'
        },
      ],
      opinionVisible: false,
      data: [],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      dataLoading: false,
      sort: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: "",
        formulateType: ""
      }
    }
  },
  async mounted() {
    await this.getDeptTreeSelect()
    await this.getList()
  },
  methods: {
    onSubmit() {
      let validateResult = true
      Object.keys(this.formData).forEach(key => {
        if (this.formData[key] == "") {
          validateResult = false
        }
      })
      if (validateResult) {
        this.formData.localId = this.nowRow.id
        this.$api.bzh.opinion.add(this.formData).then(response => {
          this.$message.success("意见提交成功")
          this.opinionVisible = false
        }).catch(e => {
          this.$message.error(e.toString())
        })
      } else {
        this.$message.warning("输入框中不能为空")
      }
    },
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data
      }).catch(e => {
        this.$message.error(e.toString())
      })
    },
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getList() {
      this.dataLoading = true
      this.queryParams.pageNum = this.pagination.current || 1
      this.$api.bzh.standard.myList(this.queryParams).then(response => {
        this.pagination.total = response.total
        this.data = response.rows
        this.dataLoading = false
      }).catch(e => {
        this.dataLoading = false
        this.$message.error(e.toString())
      })
    },
  }
}
</script>

<style lang="less" scoped>

</style>

